package com.weixing.mall.provider.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.weixing.mall.base.wrapper.Result;
import com.weixing.mall.base.wrapper.ResultUtil;
import com.weixing.mall.core.annotation.NoNeedAccess;
import com.weixing.mall.core.support.BaseController;
import com.weixing.mall.provider.model.vo.report.product.ProductSaleDetailVo;
import com.weixing.mall.provider.model.vo.report.product.ProductSaleReportVo;
import com.weixing.mall.provider.model.vo.report.product.ProductSaleVolumeDetailVo;
import com.weixing.mall.provider.model.vo.report.product.ProductSaleVolumeVo;
import com.weixing.mall.provider.service.IDayReportProductService;
import com.weixing.mall.provider.util.EasyExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;

/**
 * @author jzy
 * @date 2020/6/8
 */
@RestController
@RequestMapping("report")
@Api(value = "后台报表APi", tags = "后台报表-商品部报表")
public class ReportProductController extends BaseController {

    @Autowired
    private IDayReportProductService productService;


    @ApiOperation(value = "商品部报表--1销售报表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "catId", value = "商品分类",required = false, paramType = "query"),
            @ApiImplicitParam(name = "styleNo", value = "商品款号",required = false, paramType = "query"),
            @ApiImplicitParam(name = "goodsSn", value = "商品货号",required = false, paramType = "query"),
            @ApiImplicitParam(name = "startTime", value = "开始时间",required = false, paramType = "query"),
            @ApiImplicitParam(name = "endTime", value = "结束时间",required = false, paramType = "query"),
    })
    @GetMapping("/product/sale")
    public Result<IPage<ProductSaleReportVo>> productSaleReport(Long catId,String styleNo,String goodsSn,String startTime,String endTime){
        IPage<ProductSaleReportVo> page = productService.productSaleReport(catId, styleNo, goodsSn, startTime, endTime, initMpPage());
        return ResultUtil.success(page);
    }
    @ApiOperation(value = "商品部报表--1销售报表-导出excel")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "catId", value = "商品分类",required = false, paramType = "query"),
            @ApiImplicitParam(name = "styleNo", value = "商品款号",required = false, paramType = "query"),
            @ApiImplicitParam(name = "goodsSn", value = "商品货号",required = false, paramType = "query"),
            @ApiImplicitParam(name = "startTime", value = "开始时间",required = false, paramType = "query"),
            @ApiImplicitParam(name = "endTime", value = "结束时间",required = false, paramType = "query"),
    })
    @GetMapping("/product/sale/excel")
    @NoNeedAccess
    public void productSaleReportExcel(Long catId, String styleNo, String goodsSn, String startTime, String endTime, HttpServletResponse response){
        IPage<ProductSaleReportVo> page = productService.productSaleReport(catId, styleNo, goodsSn, startTime, endTime, new Page(1,-1));
        try {
            EasyExcelUtil.writeExcel(response,ProductSaleReportVo.class,page.getRecords(),"销售报表");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @ApiOperation(value = "商品部报表--2销售明细")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderMin", value = "订单量最小",required = false, paramType = "query"),
            @ApiImplicitParam(name = "orderMax", value = "订单量最大",required = false, paramType = "query"),
            @ApiImplicitParam(name = "stockoutMin", value = "断货量最小",required = false, paramType = "query"),
            @ApiImplicitParam(name = "stockoutMax", value = "断货量最大",required = false, paramType = "query"),
            @ApiImplicitParam(name = "cancelMin", value = "取消量最小",required = false, paramType = "query"),
            @ApiImplicitParam(name = "cancelMax", value = "取消量最大",required = false, paramType = "query"),
            @ApiImplicitParam(name = "returnMin", value = "退货量最小",required = false, paramType = "query"),
            @ApiImplicitParam(name = "returnMax", value = "退货量最大",required = false, paramType = "query"),
            @ApiImplicitParam(name = "priceMin", value = "价格最小",required = false, paramType = "query"),
            @ApiImplicitParam(name = "priceMax", value = "价格最大",required = false, paramType = "query"),
            @ApiImplicitParam(name = "orderType", value = "订单类型 1正价 2代理活动 3秒杀活动",required = false, paramType = "query"),
            @ApiImplicitParam(name = "actId", value = "活动Id",required = false, paramType = "query"),
            @ApiImplicitParam(name = "color", value = "颜色",required = false, paramType = "query"),
            @ApiImplicitParam(name = "startTime", value = "开始时间",required = false, paramType = "query"),
            @ApiImplicitParam(name = "endTime", value = "结束时间",required = false, paramType = "query"),
            @ApiImplicitParam(name = "goodsSn", value = "货号",required = false, paramType = "query"),
    })
    @GetMapping("/product/sale/detail")
    public Result<IPage<ProductSaleDetailVo>> productSaleDetail(Integer orderMin,
                                                                Integer orderMax,
                                                                Integer stockoutMin,
                                                                Integer stockoutMax,
                                                                Integer cancelMin,
                                                                Integer cancelMax,
                                                                Integer returnMin,
                                                                Integer returnMax,
                                                                BigDecimal priceMin,
                                                                BigDecimal priceMax,
                                                                Integer orderType,
                                                                Long actId,
                                                                String color,
                                                                String startTime,
                                                                String endTime,
                                                                String goodsSn){
        IPage<ProductSaleDetailVo> page = productService.productSaleDetail(orderMin,orderMax,stockoutMin,stockoutMax,cancelMin,cancelMax,returnMin,returnMax,priceMin,priceMax,orderType,actId, color, startTime, endTime,goodsSn, initMpPage());
        return ResultUtil.success(page);
    }
    @ApiOperation(value = "商品部报表--2销售明细-导出excel")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderMin", value = "订单量最小",required = false, paramType = "query"),
            @ApiImplicitParam(name = "orderMax", value = "订单量最大",required = false, paramType = "query"),
            @ApiImplicitParam(name = "stockoutMin", value = "断货量最小",required = false, paramType = "query"),
            @ApiImplicitParam(name = "stockoutMax", value = "断货量最大",required = false, paramType = "query"),
            @ApiImplicitParam(name = "cancelMin", value = "取消量最小",required = false, paramType = "query"),
            @ApiImplicitParam(name = "cancelMax", value = "取消量最大",required = false, paramType = "query"),
            @ApiImplicitParam(name = "returnMin", value = "退货量最小",required = false, paramType = "query"),
            @ApiImplicitParam(name = "returnMax", value = "退货量最大",required = false, paramType = "query"),
            @ApiImplicitParam(name = "priceMin", value = "价格最小",required = false, paramType = "query"),
            @ApiImplicitParam(name = "priceMax", value = "价格最大",required = false, paramType = "query"),
            @ApiImplicitParam(name = "actType", value = "活动分类 1代理商活动 2秒杀活动",required = false, paramType = "query"),
            @ApiImplicitParam(name = "actId", value = "活动Id",required = false, paramType = "query"),
            @ApiImplicitParam(name = "color", value = "颜色",required = false, paramType = "query"),
            @ApiImplicitParam(name = "startTime", value = "开始时间",required = false, paramType = "query"),
            @ApiImplicitParam(name = "endTime", value = "结束时间",required = false, paramType = "query"),
            @ApiImplicitParam(name = "goodsSn", value = "商品吗",required = false, paramType = "query"),
    })
    @GetMapping("/product/sale/detail/excel")
    @NoNeedAccess
    public void productSaleDetailExcel(Integer orderMin,
                                       Integer orderMax,
                                       Integer stockoutMin,
                                       Integer stockoutMax,
                                       Integer cancelMin,
                                       Integer cancelMax,
                                       Integer returnMin,
                                       Integer returnMax,
                                       BigDecimal priceMin,
                                       BigDecimal priceMax,
                                       Integer actType,
                                       Long actId,
                                       String color,
                                       String startTime,
                                       String endTime,
                                       String goodsSn,
                                       HttpServletResponse response){
        IPage<ProductSaleDetailVo> page = productService.productSaleDetail(orderMin,orderMax,stockoutMin,stockoutMax,cancelMin,cancelMax,returnMin,returnMax,priceMin,priceMax,actType,actId, color, startTime, endTime,goodsSn, new Page(1,-1));
        try {
            EasyExcelUtil.writeExcel(response,ProductSaleDetailVo.class,page.getRecords(),"销售明细");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @ApiOperation(value = "商品部报表--3商品销量报表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "actId", value = "活动Id",required = false, paramType = "query"),
            @ApiImplicitParam(name = "color", value = "颜色",required = false, paramType = "query"),
            @ApiImplicitParam(name = "startTime", value = "开始时间",required = false, paramType = "query"),
            @ApiImplicitParam(name = "endTime", value = "结束时间",required = false, paramType = "query"),
    })
    @GetMapping("/product/sale/volume")
    public Result<IPage<ProductSaleVolumeVo>> productSaleVolume(Long actId,String color,String startTime,String endTime){
        IPage<ProductSaleVolumeVo> page = productService.productSaleVolume(actId, color, startTime, endTime, initMpPage());
        return ResultUtil.success(page);
    }
    @ApiOperation(value = "商品部报表--3商品销量报表-导出excel")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "actId", value = "活动Id",required = false, paramType = "query"),
            @ApiImplicitParam(name = "color", value = "颜色",required = false, paramType = "query"),
            @ApiImplicitParam(name = "startTime", value = "开始时间",required = false, paramType = "query"),
            @ApiImplicitParam(name = "endTime", value = "结束时间",required = false, paramType = "query"),
    })
    @GetMapping("/product/sale/volume/excel")
    @NoNeedAccess
    public void productSaleVolumeExcel(Long actId,String color,String startTime,String endTime,HttpServletResponse response){
        IPage<ProductSaleVolumeVo> page = productService.productSaleVolume(actId, color, startTime, endTime, new Page(1,-1));
        try {
            EasyExcelUtil.writeExcel(response,ProductSaleVolumeVo.class,page.getRecords(),"商品销量报表");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    @ApiOperation(value = "商品部报表--3商品销量报表-详细数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "类型 1订单数量  2 断货量 3取消量 4退货量",required = false, paramType = "query"),
            @ApiImplicitParam(name = "actId", value = "活动Id",required = false, paramType = "query"),
            @ApiImplicitParam(name = "color", value = "颜色",required = false, paramType = "query"),
            @ApiImplicitParam(name = "size", value = "尺寸",required = false, paramType = "query"),
            @ApiImplicitParam(name = "startTime", value = "开始时间",required = false, paramType = "query"),
            @ApiImplicitParam(name = "endTime", value = "结束时间",required = false, paramType = "query"),
    })
    @GetMapping("/product/sale/volume/detail")
    public Result<IPage<ProductSaleVolumeDetailVo>> productSaleVolumeDetail(Integer type,Long actId,String color,String startTime,String endTime){
        IPage<ProductSaleVolumeDetailVo> page = productService.productSaleVolumeDetail(type, actId, color, startTime, endTime, initMpPage());
        return ResultUtil.success(page);
    }
    @ApiOperation(value = "商品部报表--3商品销量报表-详细数据-导出excel")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "类型 1订单数量  2 断货量 3取消量 4退货量",required = false, paramType = "query"),
            @ApiImplicitParam(name = "actId", value = "活动Id",required = false, paramType = "query"),
            @ApiImplicitParam(name = "color", value = "颜色",required = false, paramType = "query"),
            @ApiImplicitParam(name = "size", value = "尺寸",required = false, paramType = "query"),
            @ApiImplicitParam(name = "startTime", value = "开始时间",required = false, paramType = "query"),
            @ApiImplicitParam(name = "endTime", value = "结束时间",required = false, paramType = "query"),
    })
    @GetMapping("/product/sale/volume/detail/excel")
    @NoNeedAccess
    public void productSaleVolumeDetailExcel(Integer type,Long actId,String color,String startTime,String endTime,HttpServletResponse response){
        IPage<ProductSaleVolumeDetailVo> page = productService.productSaleVolumeDetail(type, actId, color, startTime, endTime, initMpPage());
        try {
            EasyExcelUtil.writeExcel(response,ProductSaleVolumeDetailVo.class,page.getRecords(),"商品销量明细");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
